import 'dart:collection';

import 'package:bruno/bruno.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_nft/api/API.dart';
import 'package:flutter_nft/provider/LoginProvider.dart';
import 'package:provider/provider.dart';

class MyIndexPro extends StatefulWidget {
  @override
  _MyIndexProState createState() => _MyIndexProState();
}

class _MyIndexProState extends State<MyIndexPro> {

  Map userMap = new HashMap();
  
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    print("我的个人中心打印缓存...");
    print(context.read<LoginProvider>().isLogin.toString());
    print(context.read<LoginProvider>().getUserName().toString());

    getUser();
  }
  
  getUser()async{
    if(context.read<LoginProvider>().isLogin){
      var result = await new Dio().get(API.reqUrl+"/api/GxUser/get/by/"+context.read<LoginProvider>().getUserName());
      if(result.data != null){
        setState(() {
          userMap = result.data["dataObj"];
        });
      }

    }
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    userMap;
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.all(15),
      child: Container(
        width: MediaQuery.of(context).size.width,
        height: MediaQuery.of(context).size.height,
        //decoration: BoxDecoration(color: Colors.black54),
        child: ListView(
          children: [
            SizedBox(
              height: 40,
            ),
            Container(
              width: MediaQuery.of(context).size.width,
              height: 70,
              alignment: Alignment.centerLeft,
              //decoration: BoxDecoration(color: Colors.green),
              child: Row(
                children: [
                  InkWell(
                  onTap:(){
                    if(!context.read<LoginProvider>().isLogin){
                      Navigator.of(context).pushNamed("registertwo");
                    }
                  },
                    child: Container(
                      width: 70,
                      height: 70,
                      decoration: BoxDecoration(
                        color: Color.fromRGBO(240, 225, 192, 1),
                        borderRadius: BorderRadius.circular(70),
                      ),
                      child: Icon(Icons.account_circle,size: 50,),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.only(top: 5, bottom: 6, left: 10),
                    child: Container(
                      width: 200,
                      height: 70,
                      alignment: Alignment.centerLeft,
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.spaceAround,
                        children: [
                          Container(
                            //color: Colors.teal,
                              alignment: Alignment.centerLeft,
                              width: 200,
                              child: Text(
                                context.read<LoginProvider>().isLogin?userMap["userName"].toString(): "未登录",
                                textAlign: TextAlign.left,
                                style: TextStyle(
                                    fontSize: 20,
                                    color: Colors.white,
                                    fontWeight: FontWeight.w600),
                              )),
                          context.read<LoginProvider>().isLogin? Container(
                            //color: Colors.white70,
                              alignment: Alignment.centerLeft,
                              width: 200,
                              child: Text(
                                userMap["gxDesc"].toString() == "null"?"添加你的个性签名吧":userMap["gxDesc"].toString(),
                                textAlign: TextAlign.left,
                              )):
                          Container(
                            //color: Colors.white70,
                              alignment: Alignment.centerLeft,
                              width: 200,
                              child: Text(
                                "登录后可查看您的买的产品",
                                textAlign: TextAlign.left,
                              )),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
            SizedBox(
              height: 10,
            ),

            //订单,,,记录  栓塞制
            Container(
              height: 100,
              width: MediaQuery.of(context).size.width,
              decoration: BoxDecoration(
                  color: Color.fromRGBO(53, 54, 56, 1),
                  borderRadius: BorderRadius.circular(10)),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  InkWell(
                    onTap: (){
                      if(context.read<LoginProvider>().isLogin){
                        Navigator.of(context).pushNamed("orderlist",arguments: "");
                      }else{
                        Navigator.of(context).pushNamed("registertwo");
                      }
                    },
                    child: Container(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Icon(
                            Icons.reorder_outlined,
                            size: 33,
                          ),
                          Text(
                            "我的订单",
                            style: TextStyle(fontSize: 16, color: Colors.white24),
                          )
                        ],
                      ),
                    ),
                  ),
                  Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Icon(
                        Icons.star,
                        size: 30,
                      ),
                      Text(
                        "产品记录",
                        style: TextStyle(fontSize: 16, color: Colors.white24),
                      )
                    ],
                  ),
                  InkWell(
                    onTap: (){
                      Navigator.of(context).pushNamed("clearsetting",arguments: "");
                    },
                    child: Container(


                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Icon(
                            Icons.settings,
                            size: 30,
                          ),
                          Text(
                            "设置",
                            style: TextStyle(fontSize: 16, color: Colors.white24),
                          )
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
            //查询,,安全,客服.....
            SizedBox(
              height: 10,
            ),
            InkWell(
              onTap: () {
                BrnToast.show(
                  "敬请期待..",
                  context,
                  // preIcon: Image.asset(
                  //   "assets/image/icon_toast_success.png",
                  //   width: 24,
                  //   height: 24,
                  // ),
                  duration: BrnDuration.short,
                );
              },
              child: Container(
                width: MediaQuery.of(context).size.width,
                height: 68,
                decoration: BoxDecoration(
                    color: Color.fromRGBO(41, 43, 42, 1),
                    borderRadius: BorderRadius.circular(18)),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Row(
                      children: [
                        SizedBox(
                          width: 10,
                        ),
                        Icon(
                          Icons.search,
                          size: 25,
                        ),
                        SizedBox(
                          width: 10,
                        ),
                        Text(
                          "信息查询",
                          style: TextStyle(color: Colors.white, fontSize: 16),
                        )
                      ],
                    ),
                    Padding(
                        padding: EdgeInsets.only(right: 15), child: Text(">")),
                  ],
                ),
              ),
            ),
            SizedBox(
              height: 10,
            ),
            InkWell(
              onTap: () {
                BrnToast.show(
                  "敬请期待..",
                  context,
                  // preIcon: Image.asset(
                  //   "assets/image/icon_toast_success.png",
                  //   width: 24,
                  //   height: 24,
                  // ),
                  duration: BrnDuration.short,
                );
              },
              child: Container(
                width: MediaQuery.of(context).size.width,
                height: 68,
                decoration: BoxDecoration(
                    color: Color.fromRGBO(41, 43, 42, 1),
                    borderRadius: BorderRadius.circular(18)),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Row(
                      children: [
                        SizedBox(
                          width: 10,
                        ),
                        Icon(
                          Icons.supervisor_account_sharp,
                          size: 25,
                        ),
                        SizedBox(
                          width: 10,
                        ),
                        Text(
                          "账号与安全",
                          style: TextStyle(color: Colors.white, fontSize: 16),
                        )
                      ],
                    ),
                    Padding(
                        padding: EdgeInsets.only(right: 15), child: Text(">")),
                  ],
                ),
              ),
            ),
            SizedBox(
              height: 10,
            ),
            InkWell(
              onTap: () {
                BrnToast.show(
                  "敬请期待..",
                  context,
                  // preIcon: Image.asset(
                  //   "assets/image/icon_toast_success.png",
                  //   width: 24,
                  //   height: 24,
                  // ),
                  duration: BrnDuration.short,
                );
              },
              child: Container(
                width: MediaQuery.of(context).size.width,
                height: 68,
                decoration: BoxDecoration(
                    color: Color.fromRGBO(41, 43, 42, 1),
                    borderRadius: BorderRadius.circular(18)),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Row(
                      children: [
                        SizedBox(
                          width: 10,
                        ),
                        Icon(
                          Icons.wifi_calling,
                          size: 25,
                        ),
                        SizedBox(
                          width: 10,
                        ),
                        Text(
                          "我的客服",
                          style: TextStyle(color: Colors.white, fontSize: 16),
                        )
                      ],
                    ),
                    Padding(
                        padding: EdgeInsets.only(right: 15), child: Text(">")),
                  ],
                ),
              ),
            ),
            SizedBox(
              height: 10,
            ),
            InkWell(
              onTap: () {
                BrnToast.show(
                  "敬请期待..",
                  context,
                  // preIcon: Image.asset(
                  //   "assets/image/icon_toast_success.png",
                  //   width: 24,
                  //   height: 24,
                  // ),
                  duration: BrnDuration.short,
                );
              },
              child: Container(
                width: MediaQuery.of(context).size.width,
                height: 68,
                decoration: BoxDecoration(
                    color: Color.fromRGBO(41, 43, 42, 1),
                    borderRadius: BorderRadius.circular(18)),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Row(
                      children: [
                        SizedBox(
                          width: 10,
                        ),
                        Icon(
                          Icons.all_inclusive,
                          size: 25,
                        ),
                        SizedBox(
                          width: 10,
                        ),
                        Text(
                          "关于古谢",
                          style: TextStyle(color: Colors.white, fontSize: 16),
                        )
                      ],
                    ),
                    Padding(
                        padding: EdgeInsets.only(right: 15), child: Text(">")),
                  ],
                ),
              ),
            ),
            SizedBox(
              height: 10,
            ),
            InkWell(
              onTap: () {
                BrnToast.show(
                  "敬请期待..",
                  context,
                  // preIcon: Image.asset(
                  //   "assets/image/icon_toast_success.png",
                  //   width: 24,
                  //   height: 24,
                  // ),
                  duration: BrnDuration.short,
                );
              },
              child: Container(
                width: MediaQuery.of(context).size.width,
                height: 68,
                decoration: BoxDecoration(
                    color: Color.fromRGBO(41, 43, 42, 1),
                    borderRadius: BorderRadius.circular(18)),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Row(
                      children: [
                        SizedBox(
                          width: 10,
                        ),
                        Icon(
                          Icons.star,
                          size: 25,
                        ),
                        SizedBox(
                          width: 10,
                        ),
                        Text(
                          "分享古谢",
                          style: TextStyle(color: Colors.white, fontSize: 16),
                        ),
                      ],
                    ),
                    Padding(
                        padding: EdgeInsets.only(right: 15), child: Text(">")),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}



